package cn.ivicar.iov.util;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.List;

/**
 * @Author: Chen
 * @Description:数据导出工具类
 * @Date: Created in 20:01 2018/8/21
 */
public class OutputUtil {
    public static Workbook getExcel(List<String> list){
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet =wb.createSheet("流量卡业务详情表");//创建sheet

        HSSFFont font = wb.createFont();
        font.setFontName("微软雅黑");//设置字体为微软雅黑
        font.setBold(true);//粗体
        font.setFontHeightInPoints((short)12);//字体大小

        HSSFCellStyle cellStyle1 = wb.createCellStyle();
        cellStyle1.setFont(font);//字体风格
        HSSFRow row = null;

        row = sheet.createRow(0);
        row.createCell(0).setCellValue("iccid");
        row.getCell(0).setCellStyle(cellStyle1);

        for (int i=0;i<list.size();i++){
            row = sheet.createRow(i+1);
            row.createCell(0).setCellValue(list.get(i));
        }

        //列宽自适应
        sheet.autoSizeColumn(0);
        return wb;
    }
}
